import os
import datetime
import wave
import logging
async def save_wave_file(audio_data, folder='recive_audio_records', channels=1, sampwidth=2, framerate=16000):
    try:
        if not os.path.exists(folder):
            os.makedirs(folder)
        current_time = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
        filename = f"{current_time}.wav"
        file_path = os.path.join(folder, filename)
        
        with wave.open(file_path, 'wb') as wf:
            wf.setnchannels(channels)
            wf.setsampwidth(sampwidth)
            wf.setframerate(framerate)
            wf.writeframes(audio_data)
        logging.info(f"audio_data saved as {file_path}")
        return file_path
    except Exception as e:
        logging.error(f"Error in save_wave_file: {e}")
